public class UrlEncode {
 /**
  * convert String to Hex
  * 
  * @param str
  * @return
  */
 public static String toHexString(String str) {
  byte[] byStr = str.getBytes();

  return parseArr(byStr);
 }

 /**
  * convert Hex to String
  * @param s
  * @return
  */
 public static String toStringHex(String s) {
  byte[] byStr = new byte[s.length() / 2];
  for (int i = 0; i < byStr.length; i++) {
   try {
    byStr[i] = (byte) (0xff & Integer.parseInt(s.substring(
      i * 2, i * 2 + 2), 16));
   } catch (Exception e) {
    e.printStackTrace();
   }
  }

  try {
   s = new String(byStr, "utf-8");// UTF-16le:Not
  } catch (Exception e1) {
   e1.printStackTrace();
  }
  return s;
 }
 
 private static String parseArr(byte[] byStr){
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < byStr.length; i++) {
   sb.append("%" + Integer.toHexString(byStr[i]));
  }
  
  return sb.toString();
 }

 public static void main(String[] args) {
  String str = "Happy";
  System.out.println(UrlEncode.toHexString(str));
  System.out.println(UrlEncode.toStringHex(UrlEncode.toHexString(str)));
 }
}